package com.echo.im.platform.manager;

import com.echo.im.client.facade.IMClient;
import com.echo.im.common.model.message.IMSystemMessage;
import com.echo.im.common.vo.message.SystemMessageVO;
import com.echo.im.mq.event.model.PrivateStoreMessageEvent;
import com.echo.im.mq.event.model.SystemStoreMessageEvent;
import com.echo.im.mq.event.producer.EventPublisher;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * @author: echo
 * @time: 2024-08-17
 */
@Component
@RequiredArgsConstructor
public class SystemMessageManager {

    private final IMClient imClient;
    private final EventPublisher eventPublisher;
    private final SystemStoreMessageEvent systemStoreMessageEvent;

    public void sendAndSave(IMSystemMessage imSystemMessage) {
        // 推送消息
        imClient.sendMessage(imSystemMessage);

        // 持久化存储
        eventPublisher.publish(systemStoreMessageEvent.topic(), systemStoreMessageEvent.buildEventMessage(imSystemMessage.getData()));

    }
}
